import pygame

from src.constants import Direction


class LandScape(pygame.sprite.Sprite):

    def __init__(self):
        super().__init__()
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = False


class Home(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/home.png')
        self.rect = self.image.get_rect()
        self.rect.topleft = (3 + 6 * 48, 3 + 12 * 48)
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = False


class DestroyedHome(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/destroyed_home.png')
        self.rect = self.image.get_rect()
        self.rect.topleft = (3 + 6 * 48, 3 + 12 * 48)
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = False


class Brick(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/brick.png')
        self.rect = self.image.get_rect()
        self.is_half_brick = False
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = False

    def get_half(self, direction):
        left = self.rect.left
        top = self.rect.top
        if direction == Direction.LEFT:
            self.image = self.image.subsurface((0, 0, 12, 24))
        elif direction == Direction.UP:
            self.image = self.image.subsurface((0, 0, 24, 12))
        elif direction == Direction.RIGHT:
            self.image = self.image.subsurface((12, 0, 12, 24))
            left += 12
        elif direction == Direction.DOWN:
            self.image = self.image.subsurface((0, 12, 24, 12))
            top += 12
        self.rect = self.image.get_rect()
        self.rect.left = left
        self.rect.top = top
        self.is_half_brick = True
        return self

class Steel(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/steel.png')
        self.rect = self.image.get_rect()
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = False


class Ice(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/ice.png')
        self.rect = self.image.get_rect()
        self.can_cross_by_tank = True
        self.can_cross_by_bullet = True


class River(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/river.png')
        self.rect = self.image.get_rect()
        self.can_cross_by_tank = False
        self.can_cross_by_bullet = True


class Wood(LandScape):

    def __init__(self):
        super().__init__()
        self.image = pygame.image.load('assets/images/landscape/wood.png')
        self.rect = self.image.get_rect()
        self.can_cross_by_tank = True
        self.can_cross_by_bullet = True


# 地形映射
LANDSCAPE_MAP = {
    '1': Brick,
    '2': Steel,
    '3': Ice,
    '4': River,
    '5': Wood
}